package choreganizer;

import java.io.*;
import java.util.*;
import java.util.prefs.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.util.regex.*;
import java.util.Calendar;
import java.util.GregorianCalendar;


// Maybe extend dialog instead
public class EditDialog
extends JDialog
implements ActionListener
{
	// Enum of the type of action we're doing
	private enum STATE {
		START, CONFIRM_FINISH,
		CHORE_ADD, CHORE_DEL_1, CHORE_DEL_2, CHORE_EDIT_1, CHORE_EDIT_2,
		SCHED_ADD_CHORE, SCHED_ADD_1, SCHED_ADD_2, SCHED_ADD_3, SCHED_ADD_4, SCHED_ADD_5, SCHED_ADD_6,
		SCHED_DEL_1, SCHED_DEL_CHORE, SCHED_DEL_2, SCHED_DEL_3, SCHED_DEL_4, SCHED_DEL_5, SCHED_DEL_6, SCHED_DEL_7,
		SCHED_EDIT_1, SCHED_EDIT_CHORE, SCHED_EDIT_2, SCHED_EDIT_3, SCHED_EDIT_4, SCHED_EDIT_5, SCHED_EDIT_6, SCHED_EDIT_7
	};
	private STATE currState;
	
	private String noChoreStr = "- No Chores Exist -";
	private String noSchedStr = "- No Schedules Exist -";
	
	// Temp info we'll hold about a Chore or Schedule we're configuring
	private ChoreData tempChore;
	private ScheduleData tempSched;
	
	// Complete list of all chores and schedules
	private ChoreData[] chores;
	private ScheduleData[] schedules;
	
	// The main JFrame
	private JFrame owner;
	// Content pane for the JDialog
	private JPanel contentPanel;
	
	// Buttons we will use to move through the processes
	private JPanel buttonPanel;
	private JButton btn_quit = new JButton("Close");
	private JButton btn_cancel = new JButton("Cancel");
	private JButton btn_back = new JButton("Back");
	private JButton btn_next = new JButton("Next");
	private JButton btn_finish = new JButton("Finish");
	private JButton btn_delete = new JButton("Delete");
	
	// Radio buttons for the type of task we want to do
	private ButtonGroup group;
	private JRadioButton addChore = new JRadioButton("Add a new Chore");
	private JRadioButton addSched = new JRadioButton("Add a new chore Schedule");
	private JRadioButton editChore = new JRadioButton("Edit an existing Chore");
	private JRadioButton editSched = new JRadioButton("Edit an existing chore Schedule");
	private JRadioButton delChore = new JRadioButton("Delete an existing Chore");
	private JRadioButton delSched = new JRadioButton("Delete an existing chore Schedule");
	
	// If we performed an add/delete/edit
	private boolean needToUpdate;
	
	
	
	public EditDialog(JFrame owner,ChoreData[] chores, ScheduleData[] schedules)
	{
		super(owner,"Chore Scheduling",true);
		
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		
		currState = STATE.START;
		
		this.owner = owner;
		
		// Make sure these aren't null
		if (chores != null)
			this.chores = chores;
		else
			this.chores = new ChoreData[0];
		if (schedules != null)
			this.schedules = schedules;
		else
			this.schedules = new ScheduleData[0];
		
		needToUpdate = false;
		
		buttonPanel = new JPanel();
		buttonPanel.setLayout( new FlowLayout(FlowLayout.RIGHT) );
		
		buttonPanel.add( btn_quit );
		buttonPanel.add( btn_cancel );
		buttonPanel.add( btn_back );
		buttonPanel.add( btn_next );
		buttonPanel.add( btn_finish );
		buttonPanel.add( btn_delete );
		
		btn_quit.addActionListener(this);
		btn_cancel.addActionListener(this);
		btn_back.addActionListener(this);
		btn_next.addActionListener(this);
		btn_finish.addActionListener(this);
		btn_delete.addActionListener(this);
		
		btn_back.setEnabled(false);
		btn_next.setEnabled(false);
		btn_finish.setEnabled(false);
		btn_delete.setEnabled(false);
		
		btn_cancel.setVisible(false);
		btn_finish.setVisible(false);
		btn_delete.setVisible(false);
		
		contentPanel = new JPanel();
		contentPanel.setLayout( new BorderLayout() );
		contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
		JScrollPane holder = new JScrollPane( mainSelectPanel() );
		holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
		contentPanel.add( holder, BorderLayout.CENTER );
		
		setContentPane( contentPanel );
		
		setSize(390,400);
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation( (screen.width - getSize().width)/2, (screen.height - getSize().height)/2 );
      setResizable(false);
      setVisible(true);
	}
	
	
	public ScheduleData[] getSchedules()
	{
		return schedules;
	}
	
	
	public ChoreData[] getChores()
	{
		return chores;
	}
	
	
	public boolean needToUpdate()
	{
		return needToUpdate;
	}
	
	
	public void setVisible(boolean visibility)
	{
		if (visibility)
			needToUpdate = false;
		super.setVisible(visibility);
	}
	
	
	/*
	* Small little listener to enable the next button when
	* an action is selected
	*/
	class RadioButtonListener
	implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			btn_next.setEnabled(true);
		}
	}
	
	
	/*
	* Used to insert chore values into a chore item
	*
	*/
	class ChoreDocListener
	implements DocumentListener
	{
		private boolean btn_nextCheck;
		private int whichItem;
		
		public ChoreDocListener(boolean btn_nextCheck, int whichItem)
		{
			this.btn_nextCheck = btn_nextCheck;
			this.whichItem = whichItem;
		}
		
		public void changedUpdate(DocumentEvent e)
		{
			doCheck(e);
		}
		public void insertUpdate(DocumentEvent e)
		{
			doCheck(e);
		}
		public void removeUpdate(DocumentEvent e)
		{
			doCheck(e);
		}
		
		public void doCheck(DocumentEvent e)
		{
			Document d = e.getDocument();
			String text = "";
			try { 
				text = d.getText(0,d.getLength());
			} catch (Exception e2) {
				//
			}
			text.trim();
			
			// Make sure it's not all empty spaces
			Pattern p = Pattern.compile(".*[^\\s]+.*");
			Matcher m = p.matcher(text);
 			boolean b = m.matches();
			
			if (btn_nextCheck)
			{
				if (b)
					btn_finish.setEnabled(true);
				else
					btn_finish.setEnabled(false);
			}
			
			if (whichItem == 0)
				tempChore.setName(text);
			else if (whichItem == 1)
				tempChore.setDescription(text);
			else if (whichItem == 2)
				tempChore.setNotes(text);
		}
	}
 
	
	/*
	* Used to select a Chore to edit/delete from our array
	*
	*/
	class ChoreSelectListener
	implements ListSelectionListener
	{
		private JList owner;
		
		public ChoreSelectListener(JList owner)
		{
			this.owner = owner;
		}
		
		public void valueChanged(ListSelectionEvent e) 
		{
			if (e.getValueIsAdjusting() == false) 
			{
				int index = owner.getSelectedIndex();
				if (index >= 0)
					btn_next.setEnabled(true);
				
				tempChore = (ChoreData)(((ChoreData)owner.getSelectedValue()).clone());
			}
		}
	}
	
	
	/*
	*
	*
	*/
	class ScheduleSelectListener
	implements ListSelectionListener
	{
		private JList owner;
		
		public ScheduleSelectListener(JList owner)
		{
			this.owner = owner;
		}
		
		public void valueChanged(ListSelectionEvent e) 
		{
			if (e.getValueIsAdjusting() == false) 
			{
				int index = owner.getSelectedIndex();
				if (index >= 0)
					btn_next.setEnabled(true);
				
				tempSched = (ScheduleData)(((ScheduleData)owner.getSelectedValue()).clone());
			}
		}
	}
	
	
	/*
	* Changes the panels and acually perform out adds/edits/deletes
	*
	*/
	public void actionPerformed(ActionEvent e)
	{
		JButton caller = (JButton)e.getSource();
		
		// Go to next window
		if (caller == btn_next)
		{
			// Start panel - trampoline triggered from JRadioButtons
			if (currState == STATE.START)
			{
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				
				btn_cancel.setVisible(true);
				btn_quit.setVisible(false);
				btn_next.setEnabled(false);
				
				if (addChore.isSelected())
				{
					currState = STATE.CHORE_ADD;
					JScrollPane holder = new JScrollPane( chore_setProps() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
					btn_next.setVisible(false);
					btn_finish.setVisible(true);
				}
				else if (addSched.isSelected())
				{
					currState = STATE.SCHED_ADD_CHORE;
					JScrollPane holder = new JScrollPane( sched_addChore() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				}
				else if (editChore.isSelected())
				{
					currState = STATE.CHORE_EDIT_1;
					JScrollPane holder = new JScrollPane( chore_select() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				}
				else if (editSched.isSelected())
				{
					currState = STATE.SCHED_EDIT_1;
					JScrollPane holder = new JScrollPane( sched_select() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				}
				else if (delChore.isSelected())
				{
					currState = STATE.CHORE_DEL_1;
					JScrollPane holder = new JScrollPane( chore_select() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				}
				else if (delSched.isSelected())
				{
					currState = STATE.SCHED_DEL_1;
					JScrollPane holder = new JScrollPane( sched_select() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				}
				
				group.clearSelection();
			}
			
			// Select a Chore's name to edit it
			else if (currState == STATE.CHORE_EDIT_1)
			{
				currState = STATE.CHORE_EDIT_2;
				
				btn_back.setEnabled(true);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(false);
				btn_finish.setVisible(true);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( chore_setProps() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
				
				
			}
			
			else if (currState == STATE.CHORE_DEL_1)
			{
				currState = STATE.CHORE_DEL_2;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				
				btn_next.setVisible(false);
				btn_delete.setVisible(true);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( chore_setProps() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_CHORE)
			{
				currState = STATE.SCHED_ADD_1;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addYear() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_1)
			{
				currState = STATE.SCHED_ADD_2;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addMonth() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_2)
			{
				currState = STATE.SCHED_ADD_3;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addDay() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_3)
			{
				currState = STATE.SCHED_ADD_4;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addTime() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_4)
			{
				currState = STATE.SCHED_ADD_5;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addAlert() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_5)
			{
				currState = STATE.SCHED_ADD_6;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				btn_finish.setEnabled(true);
				
				btn_next.setVisible(false);
				btn_finish.setVisible(true);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addStart() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_1)
			{
				currState = STATE.SCHED_EDIT_CHORE;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editChore() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_CHORE)
			{
				currState = STATE.SCHED_EDIT_2;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editYear() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_2)
			{
				currState = STATE.SCHED_EDIT_3;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editMonth() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_3)
			{
				currState = STATE.SCHED_EDIT_4;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editDay() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_4)
			{
				currState = STATE.SCHED_EDIT_5;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editTime() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_5)
			{
				currState = STATE.SCHED_EDIT_6;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editAlert() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_6)
			{
				currState = STATE.SCHED_EDIT_7;
				
				btn_back.setEnabled(true);
				btn_next.setEnabled(false);
				btn_finish.setEnabled(true);
				
				btn_next.setVisible(false);
				btn_finish.setVisible(true);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editStart() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_1)
			{
				currState = STATE.SCHED_DEL_CHORE;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delChore() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_CHORE)
			{
				currState = STATE.SCHED_DEL_2;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delYear() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_2)
			{
				currState = STATE.SCHED_DEL_3;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delMonth() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_3)
			{
				currState = STATE.SCHED_DEL_4;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delDay() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_4)
			{
				currState = STATE.SCHED_DEL_5;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delTime() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_5)
			{
				currState = STATE.SCHED_DEL_6;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delAlert() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_6)
			{
				currState = STATE.SCHED_DEL_7;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(true);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(false);
				btn_delete.setVisible(true);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delStart() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
		}
		
		// Go back to the start
		else if (caller == btn_cancel)
		{
			tempChore = null;
			tempSched = null;
			currState = STATE.START;
			
			contentPanel.removeAll();
			contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
			JScrollPane holder = new JScrollPane( mainSelectPanel() );
			holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
			contentPanel.add( holder, BorderLayout.CENTER );
			
			btn_back.setEnabled(false);
			btn_next.setEnabled(false);
			btn_finish.setEnabled(false);
			
			btn_next.setVisible(true);
			btn_finish.setVisible(false);
			btn_delete.setVisible(false);
			btn_cancel.setVisible(false);
			btn_quit.setVisible(true);
		}
		
		// Go back to previous window
		else if (caller == btn_back)
		{
			if (currState == STATE.CHORE_EDIT_2)
			{
				currState = STATE.CHORE_EDIT_1;
				
				btn_back.setEnabled(false);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(true);
				
				btn_next.setVisible(true);
				btn_finish.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( chore_select() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.CHORE_DEL_2)
			{
				currState = STATE.CHORE_DEL_1;
				
				btn_back.setEnabled(false);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(true);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( chore_select() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_1)
			{
				currState = STATE.SCHED_ADD_CHORE;
				
				btn_back.setEnabled(false);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addChore() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_2)
			{
				currState = STATE.SCHED_ADD_1;
				
				//btn_back.setEnabled(false);
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addYear() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_3)
			{
				currState = STATE.SCHED_ADD_2;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addMonth() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_4)
			{
				currState = STATE.SCHED_ADD_3;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addDay() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_5)
			{
				currState = STATE.SCHED_ADD_4;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addTime() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_ADD_6)
			{
				currState = STATE.SCHED_ADD_5;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_finish.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_addAlert() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_CHORE)
			{
				currState = STATE.SCHED_EDIT_1;
				
				btn_back.setEnabled(false);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_select() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_2)
			{
				currState = STATE.SCHED_EDIT_CHORE;
				
				//btn_back.setEnabled(false);
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editChore() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_3)
			{
				currState = STATE.SCHED_EDIT_2;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editYear() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_4)
			{
				currState = STATE.SCHED_EDIT_3;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editMonth() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_5)
			{
				currState = STATE.SCHED_EDIT_4;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editDay() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_6)
			{
				currState = STATE.SCHED_EDIT_5;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editTime() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_EDIT_7)
			{
				currState = STATE.SCHED_EDIT_6;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_finish.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editAlert() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_CHORE)
			{
				currState = STATE.SCHED_DEL_1;
				
				btn_back.setEnabled(false);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_select() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_2)
			{
				currState = STATE.SCHED_DEL_CHORE;
				
				//btn_back.setEnabled(false);
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_editChore() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_3)
			{
				currState = STATE.SCHED_DEL_2;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delYear() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_4)
			{
				currState = STATE.SCHED_DEL_3;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delMonth() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_5)
			{
				currState = STATE.SCHED_DEL_4;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delDay() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_6)
			{
				currState = STATE.SCHED_DEL_5;
				
				btn_back.setEnabled(true);
				btn_finish.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delTime() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
			else if (currState == STATE.SCHED_DEL_7)
			{
				currState = STATE.SCHED_DEL_6;
				
				btn_back.setEnabled(true);
				btn_delete.setEnabled(false);
				btn_next.setEnabled(false);
				
				btn_next.setVisible(true);
				btn_delete.setVisible(false);
				
				contentPanel.removeAll();
				contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
				JScrollPane holder = new JScrollPane( sched_delAlert() );
				holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
				contentPanel.add( holder, BorderLayout.CENTER );
			}
			
		}

		// Delete a chore/schedule
		else if (caller == btn_delete)
		{
			if (currState == STATE.CHORE_DEL_2)
			{
				JOptionPane pane = new JOptionPane();
				int exitCheck = pane.showConfirmDialog(owner, 
					"Are you sure you want to delete this chore?\n" + 
					"All schedules for this chore will also be deleted", 
					"Delete Chore?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
		
				if (exitCheck == JOptionPane.YES_OPTION)
				{
					currState = STATE.START;
					
					// Delete the chore from the array that matches tempChore, 
					// and all scheduled items that were scheduled for that chore,
					// then write out both arrays
					java.util.List<ScheduleData> newSchedulesVector
						= new java.util.Vector<ScheduleData>();
					java.util.List<ChoreData> newChoresVector
						= new java.util.Vector<ChoreData>();
						
					for (int i=0; i < chores.length; i++)
					{
						//if (chores[i].getID() != tempChore.getID())
						if ( !chores[i].getID().equals(tempChore.getID()) )
							newChoresVector.add(chores[i]);
					}
					
					for (int i=0; i < schedules.length; i++)
					{
						//if (schedules[i].getChoreID() != tempChore.getID())
						if ( !schedules[i].getChoreID().equals(tempChore.getID()) )
							newSchedulesVector.add(schedules[i]);
					}

					chores = newChoresVector.toArray(new ChoreData[0]);
					schedules = newSchedulesVector.toArray(new ScheduleData[0]);
					newChoresVector = null;
					newSchedulesVector = null;
					
					
					needToUpdate = true;
					/*Preferences prefs = Preferences.userNodeForPackage( this.getClass() );
					File choreFile = new File( prefs.get("chores","") );
					File schedFile = new File( prefs.get("schedules","") );
					MyWriters writer = new MyWriters(choreFile,schedFile);
					writer.writeChores(chores);
					writer.writeSchedules(schedules);*/
					
					
					contentPanel.removeAll();
					contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
					JScrollPane holder = new JScrollPane( mainSelectPanel() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				
					
					btn_delete.setEnabled(false);
					btn_back.setEnabled(false);
					btn_next.setEnabled(false);
					
					btn_next.setVisible(true);
					btn_delete.setVisible(false);
					btn_cancel.setVisible(false);
					btn_quit.setVisible(true);
					
					tempChore = null;
				}
			}
			
			if (currState == STATE.SCHED_DEL_7)
			{
				JOptionPane pane = new JOptionPane();
				int exitCheck = pane.showConfirmDialog(owner, "Are you sure you want to delete this schedule?", 
									 "Delete Schedule?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
		
				if (exitCheck == JOptionPane.YES_OPTION)
				{
					currState = STATE.START;
					
					// Delete the schedule from the array that matches tempSchedule, 
					// then write out the array
					java.util.List<ScheduleData> newSchedulesVector
						= new java.util.Vector<ScheduleData>();
						
					for (int i=0; i < schedules.length; i++)
					{
						//if (schedules[i].getChoreID() != tempChore.getID())
						if ( !schedules[i].getID().equals(tempSched.getID()) )
							newSchedulesVector.add(schedules[i]);
					}
					
					schedules = newSchedulesVector.toArray(new ScheduleData[0]);
					newSchedulesVector = null;
					
					needToUpdate = true;
					/*Preferences prefs = Preferences.userNodeForPackage( this.getClass() );
					File choreFile = new File( prefs.get("chores","") );
					File schedFile = new File( prefs.get("schedules","") );
					MyWriters writer = new MyWriters(choreFile,schedFile);
					writer.writeSchedules(schedules);*/
					
					
					contentPanel.removeAll();
					contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
					JScrollPane holder = new JScrollPane( mainSelectPanel() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				
					
					btn_delete.setEnabled(false);
					btn_back.setEnabled(false);
					btn_next.setEnabled(false);
					
					btn_next.setVisible(true);
					btn_delete.setVisible(false);
					btn_cancel.setVisible(false);
					btn_quit.setVisible(true);
					
					tempSched = null;
				}
			}
		}
		
		// Add/Edit a chore/schedule
		else if (caller == btn_finish)
		{
			// Re-insert our new ChoreData item back into our ChoreData[] array,
			// and then write that array to our database
			if (currState == STATE.CHORE_ADD)
			{
				JOptionPane pane = new JOptionPane();
				int exitCheck = pane.showConfirmDialog(owner, "Are you sure you want to add this chore?", 
									 "Add Chore?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
		
				if (exitCheck == JOptionPane.YES_OPTION)
				{
					currState = STATE.START;
				
					Date dNow = new Date();
					SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm"); 
					tempChore.setDateAdded(formatter.format(dNow));
					
					
					// Put the tempChore file in with the rest of our chores,
					// and write the stream out
					ChoreData newChores[] = new ChoreData[chores.length + 1];
					for (int i=0; i < chores.length; i++)
					{
						newChores[i] = chores[i];
					}
					newChores[chores.length] = tempChore;
					chores = newChores;
					newChores = null;
					
					needToUpdate = true;
					/*Preferences prefs = Preferences.userNodeForPackage( this.getClass() );
					File choreFile = new File( prefs.get("chores","") );
					File schedFile = new File( prefs.get("schedules","") );
					MyWriters writer = new MyWriters(choreFile,schedFile);
					writer.writeChores(chores);*/
					
					
					contentPanel.removeAll();
					contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
					JScrollPane holder = new JScrollPane( mainSelectPanel() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				
					
					btn_finish.setEnabled(false);
					btn_next.setEnabled(false);
					btn_back.setEnabled(false);
					
					btn_finish.setVisible(false);
					btn_next.setVisible(true);
					btn_cancel.setVisible(false);
					btn_quit.setVisible(true);
					
					tempChore = null;
				}
			}
			
			// Re-insert our modified ChoreData item back into our ChoreData[] array,
			// and then write that array to our database
			else if (currState == STATE.CHORE_EDIT_2)
			{
				JOptionPane pane = new JOptionPane();
				int exitCheck = pane.showConfirmDialog(owner, "Are you sure you want to edit this chore?", 
									 "Edit Chore?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
		
				if (exitCheck == JOptionPane.YES_OPTION)
				{
					currState = STATE.START;
					
					// Replace the old chore in the array with the edited tempChore,
					// and then write the array out to the database
					if (chores != null)
					{
						for (int i=0; i < chores.length; i++)
						{
							if ( chores[i].getID().equals(tempChore.getID()) )
								chores[i] = tempChore;
						}
					}
					
					needToUpdate = true;
					
					
					contentPanel.removeAll();
					contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
					JScrollPane holder = new JScrollPane( mainSelectPanel() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
					
					btn_finish.setEnabled(false);
					btn_next.setEnabled(false);
					btn_back.setEnabled(false);
					
					btn_finish.setVisible(false);
					btn_next.setVisible(true);
					btn_cancel.setVisible(false);
					btn_quit.setVisible(true);
					
					tempChore = null;
				}
			}
			
			if (currState == STATE.SCHED_ADD_6)
			{
				JOptionPane pane = new JOptionPane();
				int exitCheck = pane.showConfirmDialog(owner, "Are you sure you want to add this schedule?", 
									 "Add Schedule?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
		
				if (exitCheck == JOptionPane.YES_OPTION)
				{
					currState = STATE.START;
				
					Date dNow = new Date();
					SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm"); 
					tempSched.setDateAdded(formatter.format(dNow));
					
					
					// Put the tempSched file in with the rest of our schedules,
					// and write the stream out
					ScheduleData[] newSchedules = new ScheduleData[schedules.length + 1];
					for (int i=0; i < schedules.length; i++)
					{
						newSchedules[i] = schedules[i];
					}
					newSchedules[schedules.length] = tempSched;
					schedules = newSchedules;
					newSchedules = null;
					
					needToUpdate = true;
					
					
					contentPanel.removeAll();
					contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
					JScrollPane holder = new JScrollPane( mainSelectPanel() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
				
					
					btn_finish.setEnabled(false);
					btn_next.setEnabled(false);
					btn_back.setEnabled(false);
					
					btn_finish.setVisible(false);
					btn_next.setVisible(true);
					btn_cancel.setVisible(false);
					btn_quit.setVisible(true);
					
					tempSched = null;
				}
			}
			
			if (currState == STATE.SCHED_EDIT_7)
			{
				JOptionPane pane = new JOptionPane();
				int exitCheck = pane.showConfirmDialog(owner, "Are you sure you want to edit this schedule?", 
									 "Edit Schedule?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
		
				if (exitCheck == JOptionPane.YES_OPTION)
				{
					currState = STATE.START;
					
					// Replace the old schedule in the array with the edited tempSched,
					// and then write the array out to the database
					for (int i=0; i < schedules.length; i++)
					{
						//if (schedules[i].getID() == tempSched.getID())
						if ( schedules[i].getID().equals(tempSched.getID()) )
							schedules[i] = tempSched;
					}
					
					needToUpdate = true;
					/*Preferences prefs = Preferences.userNodeForPackage( this.getClass() );
					File choreFile = new File( prefs.get("chores","") );
					File schedFile = new File( prefs.get("schedules","") );
					MyWriters writer = new MyWriters(choreFile,schedFile);
					writer.writeSchedules(schedules);*/
					
					
					contentPanel.removeAll();
					contentPanel.add( buttonPanel, BorderLayout.PAGE_END );
					JScrollPane holder = new JScrollPane( mainSelectPanel() );
					holder.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
					contentPanel.add( holder, BorderLayout.CENTER );
					
					btn_finish.setEnabled(false);
					btn_next.setEnabled(false);
					btn_back.setEnabled(false);
					
					btn_finish.setVisible(false);
					btn_next.setVisible(true);
					btn_cancel.setVisible(false);
					btn_quit.setVisible(true);
					
					tempSched = null;
				}
			}
		}
		
		// Exit the Dialog
		else if (caller == btn_quit)
		{
			setVisible(false);
			dispose();
		}
		
		validate();
		repaint();
	}
	
	
	
	
	
	
	
	
	// Selection panel for what we want to do
	public JPanel mainSelectPanel()
	{
		group = new ButtonGroup();
		group.add(addChore);
		group.add(addSched);
		group.add(editChore);
		group.add(editSched);
		group.add(delChore);
		group.add(delSched);
		
		RadioButtonListener rbl = new RadioButtonListener();
		addChore.addActionListener(rbl);
		addSched.addActionListener(rbl);
		editChore.addActionListener(rbl);
		editSched.addActionListener(rbl);
		delChore.addActionListener(rbl);
		delSched.addActionListener(rbl);
		
		
		
		GridBagConstraints gbc = new GridBagConstraints();;
		GridBagLayout gbl = new GridBagLayout();
		
		JPanel all = new JPanel();
		all.setLayout( gbl );
		
		JLabel desc = new JLabel("Pick the type of action you wish to perform");
		gbc = new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(20,6,2,6),8,8);
		gbl.setConstraints(desc, gbc);
		
		JSeparator sep = new JSeparator();
		gbc = new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,6,6),8,8);
		gbl.setConstraints(sep, gbc);
		
		gbc = new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.HORIZONTAL,new Insets(0,30,0,30),0,0);
		gbl.setConstraints(addChore, gbc);
		
		gbc = new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.HORIZONTAL,new Insets(0,30,0,30),0,0);
		gbl.setConstraints(editChore, gbc);
		
		gbc = new GridBagConstraints(0,4,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.HORIZONTAL,new Insets(0,30,0,30),0,0);
		gbl.setConstraints(delChore, gbc);
		
		
		gbc = new GridBagConstraints(0,5,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.HORIZONTAL,new Insets(20,30,0,30),0,0);
		gbl.setConstraints(addSched, gbc);
		
		gbc = new GridBagConstraints(0,6,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.HORIZONTAL,new Insets(0,30,0,30),0,0);
		gbl.setConstraints(editSched, gbc);
		
		gbc = new GridBagConstraints(0,7,1,1,0,1,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(0,30,0,30),0,0);
		gbl.setConstraints(delSched, gbc);
		
		all.add(desc);
		all.add(sep);
		all.add(addChore);
		all.add(addSched);
		all.add(editChore);
		all.add(editSched);
		all.add(delChore);
		all.add(delSched);
		
		return all;
	}
	
	
	// list of chores, which we will edit/delete
	public JPanel chore_select()
	{
		GridBagConstraints gbc = new GridBagConstraints();;
		GridBagLayout gbl = new GridBagLayout();
		
		JPanel all = new JPanel();
		all.setLayout( gbl );
		
		JLabel desc = new JLabel("Select the name of a chore to edit");
		if (currState == STATE.CHORE_DEL_1)
			desc = new JLabel("Select the name of a chore to delete");
		
		gbc = new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(20,6,2,6),8,8);
		gbl.setConstraints(desc, gbc);
		
		JSeparator sep = new JSeparator();
		gbc = new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,6,6),8,8);
		gbl.setConstraints(sep, gbc);
		
		JList list = new JList();
		JScrollPane scroll = new JScrollPane( list );
		gbc = new GridBagConstraints(0,2,1,1,0,1,GridBagConstraints.PAGE_START,GridBagConstraints.BOTH,new Insets(2,30,2,30),8,8);
		gbl.setConstraints(scroll, gbc);
		
		
		
		if (chores.length > 0)
		{
			list.setListData( chores );
		}
		else
		{
			list.setListData( new String[] {noChoreStr} );
			list.setEnabled( false );
		}
		if (tempChore != null)
		{
			for (int i=0; i < chores.length; i++)
				//if (chores[i].getID() == tempChore.getID())
				if ( chores[i].getID().equals(tempChore.getID()) )
					list.setSelectedIndex(i);
		}
		list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
		list.addListSelectionListener( new ChoreSelectListener(list) );

		all.add(desc);
		all.add(sep);
		all.add(scroll);
		
		return all;
	}
	
	
	// A chore's properties, which we will add or edit
	public JPanel chore_setProps()
	{
		if (tempChore == null)
		{
			tempChore = new ChoreData();
			
			int largestChoreID = 0;
			int choreID = 0;
			for (int i=0; i < chores.length; i++)
			{
				choreID = Integer.decode(chores[i].getID());
				if (choreID > largestChoreID)
					largestChoreID = choreID;
			}
			
			tempChore.setID( Integer.toString(largestChoreID+1) );
		}
		
		GridBagConstraints gbc = new GridBagConstraints();;
		GridBagLayout gbl = new GridBagLayout();
		
		JPanel all = new JPanel();
		all.setLayout( gbl );
		

		JLabel new_chore_name_lbl = new JLabel("Chore Name:",JLabel.RIGHT);
		JLabel new_chore_desc_lbl = new JLabel("Chore Description:",JLabel.RIGHT);
		JLabel new_chore_note_lbl = new JLabel("Chore Notes:",JLabel.RIGHT);
		
		JTextField new_chore_name = new JTextField(tempChore.getName(),15);
		JTextArea new_chore_desc = new JTextArea(tempChore.getDescription(),6,15);
		JTextArea new_chore_note = new JTextArea(tempChore.getNotes(),6,15);
		
		JScrollPane descScroll = new JScrollPane(new_chore_desc);
		JScrollPane noteScroll = new JScrollPane(new_chore_note);
		
	
		new_chore_name.getDocument().addDocumentListener( new ChoreDocListener(true,0) );
		new_chore_desc.getDocument().addDocumentListener( new ChoreDocListener(false,1) );
		new_chore_note.getDocument().addDocumentListener( new ChoreDocListener(false,2) );
		if (tempChore.getName() != null && !tempChore.getName().equals("") && currState != STATE.CHORE_DEL_2)
			btn_finish.setEnabled(true);
		
		
		JLabel desc = new JLabel("Input the values for the chore you wish to create");
		if (currState == STATE.CHORE_EDIT_2)
			desc = new JLabel("Edit the values of the chore you've selected");
		else if (currState == STATE.CHORE_DEL_2)
		{
			desc = new JLabel("View the values of the chore you've selected to delete");
			new_chore_name.setEditable(false);
			new_chore_desc.setEditable(false);
			new_chore_note.setEditable(false);
		}
		
		gbc = new GridBagConstraints(0,0,2,1,0,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(20,6,2,6),8,8);
		gbl.setConstraints(desc, gbc);
		
		JSeparator sep = new JSeparator();
		gbc = new GridBagConstraints(0,1,2,1,1,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,6,6),8,8);
		gbl.setConstraints(sep, gbc);

		gbc = new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,2,6),8,8);
		gbl.setConstraints(new_chore_name_lbl, gbc);

		gbc = new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,2,6),8,8);
		gbl.setConstraints(new_chore_desc_lbl, gbc);

		gbc = new GridBagConstraints(0,4,1,1,0,1,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,2,6),8,8);
		gbl.setConstraints(new_chore_note_lbl, gbc);
		
		gbc = new GridBagConstraints(1,2,1,1,0,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,2,6),8,8);
		gbl.setConstraints(new_chore_name, gbc);
		
		gbc = new GridBagConstraints(1,3,1,1,0,0,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,2,6),8,8);
		gbl.setConstraints(descScroll, gbc);
		
		gbc = new GridBagConstraints(1,4,1,1,0,1,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(2,6,2,6),8,8);
		gbl.setConstraints(noteScroll, gbc);
		
		all.add(desc);
		all.add(sep);
		
		all.add(new_chore_name_lbl);
		all.add(new_chore_desc_lbl);
		all.add(new_chore_note_lbl);
		
		all.add(new_chore_name);
		all.add(descScroll);
		all.add(noteScroll);
		
		return all;
	}
	
	
	
	
	
	
	// list of schedules, which we will edit/delete
	public JPanel sched_select()
	{
		JPanel all			= new JPanel();
		JLabel desc 		= new JLabel("Select the ID of a chore to edit");
		JSeparator sep 	= new JSeparator();
		JList list 			= new JList();
		JScrollPane scroll= new JScrollPane( list );
		
		
		// Populate list with the ID's of all existing schedules
		if (schedules != null && schedules.length > 0)
		{
			list.setListData( schedules );
		}
		// No schedules exist, put in a placeholder, don't let them advance
		else
		{
			list.setListData( new String[] {noSchedStr} );
			list.setEnabled( false );
		}
		
		
		// Setup the list and add listeners
		list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
		list.addListSelectionListener( new ScheduleSelectListener(list) );
		
		// Select the current tempSched in the list
		if (tempSched != null)
		{
			for (int i=0; i < schedules.length; i++)
				//if (schedules[i].getID() == tempSched.getID())
				if ( schedules[i].getID().equals(tempSched.getID()) )
				{
					list.setSelectedIndex(i);
					btn_next.setEnabled(true);
				}
		}
		
		
		// Set the layout
		GridBagConstraints gbc = new GridBagConstraints();;
		GridBagLayout gbl = new GridBagLayout();
		all.setLayout( gbl );
		gbc = new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.NORTH,GridBagConstraints.HORIZONTAL,new Insets(20,6,2,6),8,8);
		gbl.setConstraints(desc, gbc);
		gbc = new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.NORTH,GridBagConstraints.HORIZONTAL,new Insets(2,6,6,6),8,8);
		gbl.setConstraints(sep, gbc);
		gbc = new GridBagConstraints(0,2,1,1,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(2,30,2,30),8,8);
		gbl.setConstraints(scroll, gbc);

		all.add(desc);
		all.add(sep);
		all.add(scroll);
		
		return all;
	}
	
	
	public JPanel sched_addChore()
	{
		// Generate the ID for this new ScheduleData
		if (tempSched == null)
		{
			tempSched = new ScheduleData();
			
			int largestSchedID = 0;
			int schedID = 0;
			
			//if (schedules != null)
			//{
				for (int i=0; i < schedules.length; i++)
				{
					schedID = Integer.decode(schedules[i].getID());
					if (schedID > largestSchedID)
						largestSchedID = schedID;
				}
			//}
			
			tempSched.setID( Integer.toString(largestSchedID+1) );
		}
		
		JPanel p = new ConfigSched_EditChore(chores, tempSched, btn_next, "add");
		return p;
	}
	
	public JPanel sched_editChore()
	{
		JPanel p = new ConfigSched_EditChore(chores, tempSched, btn_next, "edit");
		return p;
	}
	
	public JPanel sched_delChore()
	{
		JPanel p = new ConfigSched_EditChore(chores, tempSched, btn_next, "del");
		return p;
	}
	
	
	public JPanel sched_addYear()
	{
		JPanel p = new ConfigSched_EditYear(tempSched,btn_next,"add");
		return p;
	}
	
	public JPanel sched_editYear()
	{
		JPanel p = new ConfigSched_EditYear(tempSched,btn_next,"edit");
		return p;
	}
	
	public JPanel sched_delYear()
	{
		JPanel p = new ConfigSched_EditYear(tempSched,btn_next,"del");
		return p;
	}
	
	
	public JPanel sched_addMonth()
	{
		JPanel p = new ConfigSched_EditMonth(tempSched,btn_next,"add");
		return p;
	}
	
	public JPanel sched_editMonth()
	{
		JPanel p = new ConfigSched_EditMonth(tempSched,btn_next,"edit");
		return p;
	}
	
	public JPanel sched_delMonth()
	{
		JPanel p = new ConfigSched_EditMonth(tempSched,btn_next,"del");
		return p;
	}
	
	
	public JPanel sched_addDay()
	{
		JPanel p = new ConfigSched_EditDay(tempSched,btn_next,"add");
		return p;
	}
	
	public JPanel sched_editDay()
	{
		JPanel p = new ConfigSched_EditDay(tempSched,btn_next,"edit");
		return p;
	}
	
	public JPanel sched_delDay()
	{
		JPanel p = new ConfigSched_EditDay(tempSched,btn_next,"del");
		return p;
	}
	
	
	public JPanel sched_addTime()
	{
		JPanel p = new ConfigSched_EditTime(tempSched,btn_next,"add");
		return p;
	}
	
	public JPanel sched_editTime()
	{
		JPanel p = new ConfigSched_EditTime(tempSched,btn_next,"edit");
		return p;
	}
	
	public JPanel sched_delTime()
	{
		JPanel p = new ConfigSched_EditTime(tempSched,btn_next,"del");
		return p;
	}
	
	
	public JPanel sched_addAlert()
	{
		JPanel p = new ConfigSched_EditAlert(tempSched,btn_next,"add");
		return p;
	}

	public JPanel sched_editAlert()
	{
		JPanel p = new ConfigSched_EditAlert(tempSched,btn_next,"edit");
		return p;
	}
	
	public JPanel sched_delAlert()
	{
		JPanel p = new ConfigSched_EditAlert(tempSched,btn_next,"del");
		return p;
	}
	
	
	public JPanel sched_addStart()
	{
		JPanel p = new ConfigSched_EditStart(tempSched,btn_next,"add");
		return p;
	}
	
	public JPanel sched_editStart()
	{
		JPanel p = new ConfigSched_EditStart(tempSched,btn_next,"edit");
		return p;
	}
	
	public JPanel sched_delStart()
	{
		JPanel p = new ConfigSched_EditStart(tempSched,btn_next,"del");
		return p;
	}
	
	
	
	
	
}

